﻿using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using VIT.DataHelper.DataAccess;

namespace VIT.Business
{
    public class Faq : Faq_Base
    {
        SQLSupport sqlSupport = new SQLSupport();

        #region Constructor
        public Faq(string Id = "",
                        string LanguageId = "",
                        string Question = "",
                        string AskBy = "",
                        string AnswerBy = "",
                        string Answer = "",
                        string Email = "",
                        string Address = "")
        {
            this.Id = Id;
            this.LanguageId = LanguageId;
            this.Question = Question;
            this.AnswerBy = AnswerBy;
            this.Answer = Answer;
            this.AskBy = AskBy;
            this.Email = Email;
            this.Address = Address;
        }
        #endregion

        #region Front End
        public DataTable GetList()
        {
            string strQuery = "select Id, Question, AskBy, Answer, AnswerBy, Email, Address from Faq" + 
                " where LanguageID=@LanguageID and Published=1 order by Orders";
            SqlParameter LanguageId = new SqlParameter("@LanguageID", this.LanguageId);
            return sqlSupport.ExecuteDataset(false, strQuery, LanguageId).Tables[0];
        }

        public void GetSingle()
        {
            string strQuery = "select Question, AskBy, Answer, AnswerBy, Email, Address, Orders, Published" +
                                " from Faq where Id=@Id and LanguageID=@LanguageId";
            SqlParameter Id = new SqlParameter("@Id", this.Id);
            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            DataTable dt = sqlSupport.ExecuteDataset(false, strQuery, Id, LanguageId).Tables[0];

            if (dt.Rows.Count > 0)
            {
                this.Question = dt.Rows[0]["Question"].ToString();
                this.AskBy = dt.Rows[0]["AskBy"].ToString();
                this.Answer = dt.Rows[0]["Answer"].ToString();
                this.AnswerBy = dt.Rows[0]["AnswerBy"].ToString();
                this.Email = dt.Rows[0]["Email"].ToString();
                this.Address = dt.Rows[0]["Address"].ToString();             
            }            
            else this.Id = "";
        }
        #endregion
    }
}
